package com.mds.organ.web.screens.organ;

import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.Notifications;
import com.haulmont.cuba.gui.Screens;
import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.TextField;
import com.haulmont.cuba.gui.screen.Screen;
import com.haulmont.cuba.gui.screen.Subscribe;
import com.haulmont.cuba.gui.screen.UiController;
import com.haulmont.cuba.gui.screen.UiDescriptor;
import com.mds.organ.entity.OrganType;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

@UiController("mdsorgan_TestScreen")
@UiDescriptor("test-screen.xml")
public class TestScreen extends Screen {
    @Inject
    private Screens screens;

    @Inject
    private TextField txfMsgKey;

    @Inject
    private Messages messages;

    @Inject
    private Notifications notifications;

    @Subscribe("btnOpenDistrictSelect")
    public void onBtnOpenDistrictSelectClick(Button.ClickEvent event) {
        OrganSelect os = screens.create(OrganSelect.class);
        List<OrganType> lstOT=new ArrayList<>();
        lstOT.add(OrganType.DISTRICT);
        os.setOrganTypes(lstOT);
        screens.show(os);
    }

    @Subscribe("btnShowMessage")
    public void onBtnShowMessageClick(Button.ClickEvent event) {
        String msgK = (String)txfMsgKey.getValue();
        String mainMsg = messages.getMainMessage(msgK);
        String msg = messages.getMessage(this.getClass(),msgK);

        notifications.create()
                .withCaption("消息键解析")
                .withDescription(String.format("mainMsg= %s ; \\n thisPackageMsg= %s",mainMsg,msg))
                .withHideDelayMs(-1)
                .show();
    }

}